{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c9acde5e",
   "metadata": {},
   "source": [
    "* 记录人：廖洪恩  \n",
    "* 记录时间：2022年5月17日   \n",
    "* 记录内容：优化ASR(自动语音识别)机器人  图灵机器人  "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2ef0de29",
   "metadata": {},
   "source": [
    "# 本周内容     \n",
    "## 关于麦克风包安装  \n",
    "## 优化ASR(自动语音识别)机器人   \n",
    "## 连接图灵机器人\n",
    "## 语音合成  \n",
    "## 关于麦克风包安装  \n",
    "* 1.安装 speech_recognition   \n",
    "(1).pip install SpeechRecognition  \n",
    "   \n",
    "* 2.安装 PyAudio  \n",
    "(1).Not found name \"PyAudio\" moudle  \n",
    "(2.)pip install pipwin  \n",
    "(3).pipwin install PyAudio   "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "380edef4",
   "metadata": {},
   "source": [
    "#  优化ASR(自动语音识别)机器人"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "a71af7fb",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 百度密钥\n",
    "API_KEY ='5hhk3ClVlyVDs6BoaQT75HYC'\n",
    "SECRET_KEY = 'nGhPUpw0uOxcq60auHEcB56ErhAoqMbX'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "id": "6a01e3c9",
   "metadata": {},
   "outputs": [],
   "source": [
    "from bdasr import fetch_token,asr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "id": "59f069f7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "SUCCESS WITH TOKEN: 24.e8093fb1d6abd5dd0808f81e7a1f32a6.2592000.1656314555.282335-26195899 ; EXPIRES IN SECONDS: 2592000\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'24.e8093fb1d6abd5dd0808f81e7a1f32a6.2592000.1656314555.282335-26195899'"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_token = fetch_token(API_KEY,SECRET_KEY)\n",
    "liao_token"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "id": "6b5e9aa3",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 准备音频文件\n",
    "import speech_recognition\n",
    "r = speech_recognition.Recognizer()\n",
    "with speech_recognition.Microphone() as source:\n",
    "    audio = r.listen(source)\n",
    "# 将数据保存到wav文件中\n",
    "with open(\"1.wav\", \"wb\") as f: \n",
    "    f.write(audio.get_wav_data(convert_rate=16000))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "id": "ca9f8d6c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Request time cost 0.217288\n",
      "{\"corpus_no\":\"7102684389896594073\",\"err_msg\":\"success.\",\"err_no\":0,\"result\":[\"你好呀。\"],\"sn\":\"137113280251653722578\"}\n",
      "\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'{\"corpus_no\":\"7102684389896594073\",\"err_msg\":\"success.\",\"err_no\":0,\"result\":[\"你好呀。\"],\"sn\":\"137113280251653722578\"}\\n'"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "asr(token ='24.19ca14cc3954def58dd0f01219c1dd67.2592000.1655802833.282335-26195899', AUDIO_FILE = '1.wav')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "de1c8ed2",
   "metadata": {},
   "source": [
    "# 连接图灵机器人   \n",
    "* API V2.0是基于图灵机器人平台语义理解、深度学习等核心技术，为广大开发者和企业提供的在线服务和开发接口。  \n",
    "* 连接URL：\"http://openapi.turingapi.com/openapi/api/v2\"  \n",
    "* 请求方式 \n",
    "POST  \n",
    "* 请求参数 \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "id": "bd414530",
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests,json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "id": "0a471c92",
   "metadata": {},
   "outputs": [],
   "source": [
    "TL_KEY:\"d5d5bb66f66d4da8bedb378df7adfa70\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "id": "c48dea75",
   "metadata": {},
   "outputs": [],
   "source": [
    "  def TL_API(key,text):\n",
    "    TL_URL = \"http://openapi.turingapi.com/openapi/api/v2\"\n",
    "\n",
    "    payload={\n",
    "        \"reqType\":0,\n",
    "        \"perception\": {\n",
    "            \"inputText\": {\n",
    "                \"text\": \"苹果用英语怎么说\"\n",
    "            },\n",
    "        },\n",
    "        \"userInfo\": {\n",
    "            \"apiKey\": TL_KEY,\n",
    "            \"userId\": \"000001\"\n",
    "        }\n",
    "    }\n",
    "    res = requests.post(TL_URL,data = json.dumps(payload))\n",
    "    return res.json()['results'][0]['values']['text']\n",
    "\n",
    "# dict 不等价于json\n",
    "# dict to json:json.dumps()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "id": "58bf0d37",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Request time cost 0.234649\n",
      "{\"corpus_no\":\"7102684419989486949\",\"err_msg\":\"success.\",\"err_no\":0,\"result\":[\"你好呀。\"],\"sn\":\"889774966901653722585\"}\n",
      "\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'你好呀。'"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "asr_output=eval(asr(liao_token,'1.wav'))['result'][0]\n",
    "asr_output"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5cc77db3",
   "metadata": {},
   "source": [
    "# 接入对话机器人的流程   \n",
    "* 录制音频  \n",
    "* 语音识别---（百度ASR借口）----音频转文本信息  \n",
    "* 图灵API---（进行文字输入和文字回复） \n",
    "* （待做）语音合成（文字信息输出音频）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "id": "b587645c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "SUCCESS WITH TOKEN: 24.a18fd23bf22bae77dcdb6cc136ec770d.2592000.1656314609.282335-26195899 ; EXPIRES IN SECONDS: 2592000\n",
      "Request time cost 0.275670\n",
      "{\"corpus_no\":\"7102684523631139128\",\"err_msg\":\"success.\",\"err_no\":0,\"result\":[\"讲个故事吧！\"],\"sn\":\"774403378241653722609\"}\n",
      "\n"
     ]
    },
    {
     "ename": "NameError",
     "evalue": "name 'TL_KEY' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-86-c5f7a67e467d>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m     13\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     14\u001b[0m \u001b[1;31m# 3. 图灵API\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 15\u001b[1;33m \u001b[0mTL_API\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"d5d5bb66f66d4da8bedb378df7adfa70\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0masr_output\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32m<ipython-input-83-aa8964dd79ed>\u001b[0m in \u001b[0;36mTL_API\u001b[1;34m(key, text)\u001b[0m\n\u001b[0;32m     10\u001b[0m       },\n\u001b[0;32m     11\u001b[0m       \"userInfo\": {\n\u001b[1;32m---> 12\u001b[1;33m           \u001b[1;34m\"apiKey\"\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mTL_KEY\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     13\u001b[0m           \u001b[1;34m\"userId\"\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m\"000001\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     14\u001b[0m       }\n",
      "\u001b[1;31mNameError\u001b[0m: name 'TL_KEY' is not defined"
     ]
    }
   ],
   "source": [
    "# 1. 录制音频\n",
    "import speech_recognition\n",
    "r = speech_recognition.Recognizer()\n",
    "with speech_recognition.Microphone() as source:\n",
    "    audio = r.listen(source)\n",
    "# 将数据保存到wav文件中\n",
    "with open(\"1.wav\", \"wb\") as f: \n",
    "    f.write(audio.get_wav_data(convert_rate=16000))\n",
    "    \n",
    "# 2. 语音识别\n",
    "xu_token = fetch_token(API_KEY,SECRET_KEY)\n",
    "asr_output = eval(asr(xu_token,'1.wav'))['result'][0]\n",
    "\n",
    "# 3. 图灵API\n",
    "TL_API(\"d5d5bb66f66d4da8bedb378df7adfa70\",asr_output)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d071e7c4",
   "metadata": {},
   "source": [
    "# 语音合成测试"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "id": "5490c1a1",
   "metadata": {},
   "outputs": [],
   "source": [
    "# coding=utf-8\n",
    "import sys\n",
    "import json\n",
    "\n",
    "IS_PY3 = sys.version_info.major == 3\n",
    "if IS_PY3:\n",
    "    from urllib.request import urlopen\n",
    "    from urllib.request import Request\n",
    "    from urllib.error import URLError\n",
    "    from urllib.parse import urlencode\n",
    "    from urllib.parse import quote_plus\n",
    "else:\n",
    "    import urllib2\n",
    "    from urllib import quote_plus\n",
    "    from urllib2 import urlopen\n",
    "    from urllib2 import Request\n",
    "    from urllib2 import URLError\n",
    "    from urllib import urlencode\n",
    "\n",
    "TEXT = \"欢迎使用百度语音合成。\"\n",
    "\n",
    "# 发音人选择, 基础音库：0为度小美，1为度小宇，3为度逍遥，4为度丫丫，\n",
    "# 精品音库：5为度小娇，103为度米朵，106为度博文，110为度小童，111为度小萌，默认为度小美 \n",
    "PER = 4\n",
    "# 语速，取值0-15，默认为5中语速\n",
    "SPD = 5\n",
    "# 音调，取值0-15，默认为5中语调\n",
    "PIT = 5\n",
    "# 音量，取值0-9，默认为5中音量\n",
    "VOL = 5\n",
    "# 下载的文件格式, 3：mp3(default) 4： pcm-16k 5： pcm-8k 6. wav\n",
    "AUE = 6\n",
    "\n",
    "FORMATS = {3: \"mp3\", 4: \"pcm\", 5: \"pcm\", 6: \"wav\"}\n",
    "FORMAT = FORMATS[AUE]\n",
    "\n",
    "CUID = \"123456PYTHON\"\n",
    "\n",
    "TTS_URL = 'http://tsn.baidu.com/text2audio'\n",
    "\n",
    "\n",
    "class DemoError(Exception):\n",
    "    pass\n",
    "\n",
    "\n",
    "\"\"\"  TOKEN start \"\"\"\n",
    "\n",
    "TOKEN_URL = 'http://aip.baidubce.com/oauth/2.0/token'\n",
    "SCOPE = 'audio_tts_post'  # 有此scope表示有tts能力，没有请在网页里勾选\n",
    "\n",
    "\n",
    "#def fetch_token():\n",
    "#    print(\"fetch token begin\")\n",
    "#    params = {'grant_type': 'client_credentials',\n",
    "#              'client_id': API_KEY,\n",
    "#             'client_secret': SECRET_KEY}\n",
    "#    post_data = urlencode(params)\n",
    "#    if (IS_PY3):\n",
    "#        post_data = post_data.encode('utf-8')\n",
    "#    req = Request(TOKEN_URL, post_data)\n",
    "#    try:\n",
    "#        f = urlopen(req, timeout=5)\n",
    "#        result_str = f.read()\n",
    "#    except URLError as err:\n",
    "#        print('token http response http code : ' + str(err.code))\n",
    "#        result_str = err.read()\n",
    "#    if (IS_PY3):\n",
    "#        result_str = result_str.decode()\n",
    "\n",
    "   # print(result_str)\n",
    "#    result = json.loads(result_str)\n",
    " #   print(result)\n",
    "#    if ('access_token' in result.keys() and 'scope' in result.keys()):\n",
    "#        if not SCOPE in result['scope'].split(' '):\n",
    "#            raise DemoError('scope is not correct')\n",
    "   #     print('SUCCESS WITH TOKEN: %s ; EXPIRES IN SECONDS: %s' % (result['access_token'], result['expires_in']))\n",
    "#        return result['access_token']\n",
    "#    else:\n",
    "#        raise DemoError('MAYBE API_KEY or SECRET_KEY not correct: access_token or scope not found in token response')\n",
    "\n",
    "\n",
    "\"\"\"  TOKEN end \"\"\"\n",
    "\n",
    "\n",
    "def tts(token,TEXT):\n",
    "    tex = quote_plus(TEXT)  # 此处TEXT需要两次urlencode\n",
    "    print(tex)\n",
    "    params = {'tok': token, 'tex': tex, 'per': PER, 'spd': SPD, 'pit': PIT, 'vol': VOL, 'aue': AUE, 'cuid': CUID,\n",
    "              'lan': 'zh', 'ctp': 1}  # lan ctp 固定参数\n",
    "\n",
    "    data = urlencode(params)\n",
    "    print('test on Web Browser' + TTS_URL + '?' + data)\n",
    "\n",
    "    req = Request(TTS_URL, data.encode('utf-8'))\n",
    "    has_error = False\n",
    "    try:\n",
    "        f = urlopen(req)\n",
    "        result_str = f.read()\n",
    "\n",
    "        headers = dict((name.lower(), value) for name, value in f.headers.items())\n",
    "\n",
    "        has_error = ('content-type' not in headers.keys() or headers['content-type'].find('audio/') < 0)\n",
    "    except  URLError as err:\n",
    "        print('asr http response http code : ' + str(err.code))\n",
    "        result_str = err.read()\n",
    "        has_error = True\n",
    "\n",
    "    save_file = \"error.txt\" if has_error else 'result.' + FORMAT\n",
    "    with open(save_file, 'wb') as of:\n",
    "        of.write(result_str)\n",
    "\n",
    "    if has_error:\n",
    "        if (IS_PY3):\n",
    "            result_str = str(result_str, 'utf-8')\n",
    "        print(\"tts api  error:\" + result_str)\n",
    "\n",
    "    print(\"result saved as :\" + save_file)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "id": "3b416da9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "%E6%AC%A2%E8%BF%8E%E4%BD%BF%E7%94%A8%E7%99%BE%E5%BA%A6%E8%AF%AD%E9%9F%B3%E5%90%88%E6%88%90%E3%80%82\n",
      "test on Web Browserhttp://tsn.baidu.com/text2audio?tok=24.e8093fb1d6abd5dd0808f81e7a1f32a6.2592000.1656314555.282335-26195899&tex=%25E6%25AC%25A2%25E8%25BF%258E%25E4%25BD%25BF%25E7%2594%25A8%25E7%2599%25BE%25E5%25BA%25A6%25E8%25AF%25AD%25E9%259F%25B3%25E5%2590%2588%25E6%2588%2590%25E3%2580%2582&per=4&spd=5&pit=5&vol=5&aue=6&cuid=123456PYTHON&lan=zh&ctp=1\n",
      "result saved as :result.wav\n"
     ]
    }
   ],
   "source": [
    "tts(liao_token,TEXT)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "66f1cbe7",
   "metadata": {},
   "source": [
    "# 在jupyter当中播放音频文件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "id": "81adf184",
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'pydub'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-89-4639afd253de>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[0mpydub\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mAudioSegment\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      2\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0mpydub\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mplayback\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mplay\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      3\u001b[0m \u001b[0msong\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mAudioSegment\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfrom_wav\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'result.wav'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      4\u001b[0m \u001b[0mplay\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msong\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'pydub'"
     ]
    }
   ],
   "source": [
    "from pydub import AudioSegment\n",
    "from pydub.playback import play\n",
    "song = AudioSegment.from_wav('result.wav')\n",
    "play(song)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "388710ab",
   "metadata": {},
   "source": [
    "# 语音智能对话机器人最终版\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "id": "3b0185b5",
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'pydub'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-90-e6c27d336ee9>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mspeech_recognition\u001b[0m \u001b[1;31m# 语音音频录制模块\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[0mpydub\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mAudioSegment\u001b[0m \u001b[1;31m# 播放音频模块\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      3\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0mpydub\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mplayback\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mplay\u001b[0m \u001b[1;31m# 播放音频模块\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      4\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0mbdasr\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mfetch_token\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0masr\u001b[0m \u001b[1;31m# token 和语音识别模块\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      5\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0mbdtts\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mtts\u001b[0m \u001b[1;31m# 语音合成模块\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'pydub'"
     ]
    }
   ],
   "source": [
    "import speech_recognition # 语音音频录制模块\n",
    "from pydub import AudioSegment # 播放音频模块\n",
    "from pydub.playback import play # 播放音频模块\n",
    "from bdasr import fetch_token,asr # token 和语音识别模块\n",
    "from bdtts import tts # 语音合成模块\n",
    "\n",
    "# 1. 录制音频\n",
    "r = speech_recognition.Recognizer()\n",
    "with speech_recognition.Microphone() as source:\n",
    "    audio = r.listen(source)\n",
    "# 将数据保存到 wav文件中\n",
    "with open(\"1.wav\", \"wb\") as f: \n",
    "    f.write(audio.get_wav_data(convert_rate=16000))\n",
    "    \n",
    "# 2. 语音识别\n",
    "xu_token = fetch_token(API_KEY,SECRET_KEY)\n",
    "asr_output = eval(asr(xu_token,'1.wav'))['result'][0]\n",
    "\n",
    "# 3. 图灵API\n",
    "TL_result = TL_API(TL_KEY,asr_output)\n",
    "\n",
    "# 4. 语音合成 TTS -->产生result.wav\n",
    "tts(liao_token,TL_result)\n",
    "\n",
    "# 5. 在jupyter中进行音频播放\n",
    "song = AudioSegment.from_wav('result.wav')\n",
    "play(song)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2e60593d",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
